<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
</head>
<body>
  <button class="get">get请求</button>
  <button class="post">post请求</button>
  <button class="delete">delete请求</button>
  <button class="jsonp">jsonp请求</button>
  <script>
    $(function() {
      // get
      $('.get').click(function() {
        $.ajax({
          type: 'GET',
          url: 'http://127.0.0.1/api/get',
          data: {name: '张三', age: 18},
          success: (res) => {
            console.log(res)
          }
        })
      })
      // post
      $('.post').click(function() {
        $.ajax({
          type: 'POST',
          url: 'http://127.0.0.1/api/post',
          data: {name: 'zs', age: 10},
          success: (res) => {
            console.log(res)
          }
        })
      })
      // delete
      $('.delete').click(function() {
        $.ajax({
          type: 'DELETE',
          url: 'http://127.0.0.1/api/delete',
          data: {name: '李四', age: 50},
          success: (res) => {
            console.log(res)
          }
        })
      })
      // jsonp
      $('.jsonp').click(function() {
        $.ajax({
          type: 'GET',
          url: 'http://127.0.0.1/api/jsonp',
          dataType: 'jsonp',
          success: (res) => {
            console.log(res)
          }
        })
      })
    })
  </script>
</body>
</html>